﻿@{
    IList<NavMenu> navMenus = new List<NavMenu>();

    var routeData = MvcHelper.GetRouteData();
    object site = routeData.Values["site"];
    object pageUri = routeData.Values["pageUri"];

    string dirPath = Server.MapPath(string.Format("~/Views/Cms/{0}", site));
    if (Directory.Exists(dirPath))
    {
        string[] files = System.IO.Directory.GetFiles(dirPath);
        foreach (var file in files)
        {
            FileInfo fileInfo = new FileInfo(file);
            string fileName = fileInfo.Name.TrimString(".cshtml");
            string href = string.Format("~/cms/{0}/{1}", site, fileName);
            navMenus.Add(new NavMenu() { Href = href, Class = "", Text = fileName });
        }
    }



    IList<NavMenu> siteMenus = new List<NavMenu>();
    string siteDirPath = Server.MapPath(string.Format("~/Views/Cms"));
    if (Directory.Exists(siteDirPath))
    {
        string[] dirs = System.IO.Directory.GetDirectories(siteDirPath);
        foreach (var dir in dirs)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(dir);
            string dirName = dirInfo.Name;
            string href = string.Format("~/cms/{0}", dirName);
            siteMenus.Add(new NavMenu() { Href = href, Class = "", Text = dirName });
        }
    }
}

@if (navMenus.Count > 0)
{
    <li>
        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
            自定义频道
            &nbsp;
            <i class="ace-icon fa fa-angle-down bigger-110"></i>
        </a>
        <ul class="dropdown-menu dropdown-light-blue dropdown-caret">

            @foreach (NavMenu menu in navMenus)
            {
                <li>
                    <a href="@Url.Content(menu.Href)">
                        <i class="@menu.Class"></i>
                        @menu.Text
                    </a>
                </li>
            }
        </ul>
    </li>
}

<li class="">
    <a data-toggle="dropdown" class="dropdown-toggle" href="#">
        切换站点
        &nbsp;
        <i class="ace-icon fa fa-angle-down bigger-110"></i>
    </a>
    <ul class="dropdown-menu dropdown-light-blue dropdown-caret">
        @foreach (NavMenu menu in siteMenus)
        {
            <li>
                <a href="@Url.Content(menu.Href)">
                    <i class="@menu.Class"></i>
                    @menu.Text
                </a>
            </li>
        }
    </ul>
</li>